﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>@ViewData["title"]</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/sitecss/wtm.css">
    <link rel="stylesheet" href="/font/iconfont.css">
    <link rel="shortcut icon" href="/favicon.ico" />
</head>

<body>
    <div id="LAY_app"></div>
    <script src="/jquery.min.js"></script>
    <script src="/jquery.cookie.js"></script>
    <script src="/echarts/json-fns.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/layui/xm-select.js"></script>
    <script src="/echarts/echarts.min.js"></script>
    <script src="/echarts/chalk.js"></script>
    <script src="/echarts/essos.js"></script>
    <script src="/echarts/macarons.js"></script>
    <script src="/echarts/roma.js"></script>
    <script src="/echarts/vintage.js"></script>
    <script src="/echarts/walden.js"></script>
    <script src="/echarts/westeros.js"></script>
    <script src="/echarts/wonderland.js"></script>
    <script src="/_js/framework_layui.js?time=@DateTime.Now.Ticks"></script>
    <script src="/js/signalr/dist/browser/signalr.js"></script>
    <script>
        var DONOTUSE_IGNOREHASH = false;
        var DONOTUSE_COOKIEPRE = '@ViewData["DONOTUSE_COOKIEPRE"]';
        var DONOTUSE_WINDOWGUID = '@Guid.NewGuid().ToString().Replace("-", "")';
        layui.config({
            base: '/layuiadmin/'
            , version: '@DateTime.Now.Ticks'
        });



    </script>





    <script>


        const connection = new signalR.HubConnectionBuilder()
            .withUrl("/chathub")
            .configureLogging(signalR.LogLevel.Information)
            .build();

        async function start() {
            try {
                await connection.start();
                console.log("SignalR Connected.");
            } catch (err) {
                console.log(err);
                setTimeout(start, 5000);
            }
        };

        connection.onclose(async () => {
            await start();
        });



        // Start the connection.
        start();



        layui.config({
            layimPath: 'layuiim/dist/' //配置 layim.js 所在目录
            , layimAssetsPath: 'layuiadmin/layuiim/dist/layim-assets/' //layim 资源文件所在目录
        }).extend({
            layim: layui.cache.layimPath + 'layim' //配置 layim 组件所在的路径
        }).use('layim', function (layim) { //加载组件
            //先来个客服模式压压精
            layim.config({
                init: {
                    url: '/api/ImInfo/GetinitData' //接口地址（返回的数据格式见下文）
                    , type: 'get' //默认get，一般可不填
                    , data: {} //额外参数
                } //获取主面板列表信息，下文会做进一步介绍

                , title:"XXX单位"
                , isAudio:true
                , isVideo: true
                , notice:true

                //获取群员接口（返回的数据格式见下文）
                , members: {
                    url: '' //接口地址（返回的数据格式见下文）
                    , type: 'get' //默认get，一般可不填
                    , data: {} //额外参数
                }

                //上传图片接口（返回的数据格式见下文），若不开启图片上传，剔除该项即可
                , uploadImage: {
                    url: '/api/_file/UploadIm' //接口地址
                    , type: 'post' //默认post
                }

                //上传文件接口（返回的数据格式见下文），若不开启文件上传，剔除该项即可
                , uploadFile: {
                    url: '/api/_file/UploadIm' //接口地址
                    , type: 'post' //默认post
                }
                //扩展工具栏，下文会做进一步介绍（如果无需扩展，剔除该项即可）
                , tool: [{
                    alias: 'code' //工具别名
                    , title: '代码' //工具名称
                    , icon: '' //工具图标，参考图标文档
                }]

                , msgbox: layui.cache.dir + 'css/modules/layim/html/msgbox.html' //消息盒子页面地址，若不开启，剔除该项即可
                , find: layui.cache.dir + 'css/modules/layim/html/find.html' //发现页面地址，若不开启，剔除该项即可
                , chatLog: layui.cache.dir + 'css/modules/layim/html/chatlog.html' //聊天记录页面地址，若不开启，剔除该项即可
            })
            //发送文字消息
            layim.on('sendMessage', function (res) {
                var mine = res.mine;
                var to = res.to;
                var msg = {
                    username: mine.username,
                    avatar: mine.avatar,
                    id: mine.id,
                    type: to.type,
                    content: mine.content,
                    mine: false,
                    fromid: mine.id,
                    toid: to.id
                }
                var sendsjon = JSON.stringify(msg);
                connection.invoke("SenOneIm", sendsjon).catch(function (err) {
                    return console.error(err.toString());
                });
            });
            //接收文字消息
            connection.on("ReceiveOneIm", function (msg) {
                const obj = JSON.parse(msg);
                layim.getMessage(obj);
            });
            //上线
            connection.on("online", function (id) {              
                layim.setFriendStatus(id, 'online'); //设置指定好友在线，即头像取消置灰
            });
            //下线
            connection.on("offline", function (id) {
                layim.setFriendStatus(id, 'offline'); //设置指定好友在线，即头像置灰
            });

            //改变状态
            layim.on('online', function (status) {

                connection.invoke("ChangeStatus", status).catch(function (err) {
                    return console.error(err.toString());
                });

            });

            //修改签名
            layim.on('sign', function (value) {
                connection.invoke("ChangeSign", value).catch(function (err) {
                    return console.error(err.toString());
                });
               
            });
            //签名回调监听
            connection.on("SignBack", function (msg) {
                alert(msg)
            });

            //上传文件/图片













        });






    </script>


    @RenderBody()
</body>

</html>
